use regex::Regex;

pub fn clean_code(code: &str) -> String {
    let re = Regex::new(r"```rust\n(.*?)\n```").unwrap();
    let code = if let Some(caps) = re.captures(code) {
        caps.get(1).unwrap().as_str()
    } else {
        code
    };

    code.lines()
        .filter(|line| {
            let line = line.trim();
            !line.starts_with("//") && 
            !line.starts_with("/*") && 
            !line.starts_with("```") &&
            !line.is_empty()
        })
        .collect::<Vec<_>>()
        .join("\n")
        .trim()
        .to_string()
} 